import { lib, game, ui, get, ai, _status } from "../../../noname.js";
export default {
    name: "DALF_SP",
    character: {
        // "DALF_HonjouNia_SP": ["female", "wei", 3, 
        //     ["DALF_yuyan", "DALF_jianlu"],
        //     ["name:本条|二亚"]
        // ],
        "DALF_HimekawaYoshino_SP": ["female", "qun", 3, ["DALF_shiwen", "DALF_jidong", "DALF_shuangding"],
            ["name:氷芽川|四糸乃"]
        ],
    },
    translate: {
        "DALF_SP": "异构体",


        "DALF_HonjouNia_SP": "SP本条二亚",
        "DALF_HonjouNia_SP_ab": "本子二亚",
        "DALF_yuyan": "预言",
        "DALF_yuyan_info": "锁定技，牌堆顶的两张牌对你可见；判定开始前，你将其中一张牌置于牌堆顶。",
        "DALF_jianlu": "检录",
        "DALF_jianlu_info": "当你使用一张非转化且有对应实体的牌结算完后，你可以进行判定，若结果与你使用的牌：①花色相同，你收回你使用的牌；②颜色不同，你可以使用判定牌。出牌阶段限一次。",


        "DALF_HimekawaYoshino_SP": "冰铠四糸乃",
        "DALF_HimekawaYoshino_SP_ab": "四糸乃",
        "DALF_shiwen": "失温",
        "DALF_shiwen_info": "当你声明使用普【杀】后，你可以为此【杀】赋予冰属性，且若花色为♠，则此【杀】不能被响应。",
        "DALF_jidong": "急冻",
        "DALF_jidong_info": "你执行冰属性伤害特效时，每弃置一张♠牌，你可以再弃置其他角色一张牌，若此牌仍为♠牌，你对其造成1点伤害。",
        "DALF_shuangding": "霜定",
        "DALF_shuangding_marktag": "霜定",
        "DALF_shuangding_info": "出牌阶段限一次，若你手牌中因此技能摸到的牌数小于四，你可以弃置一张黑色手牌，摸一张牌。每回合限四次，你失去以此法摸到的牌时摸一张牌，若此时在你的回合外，你获得1点护甲。",

    },
    /** @type { importCharacterConfig['skill'] } */
    skill: {
        /*SP本条二亚*/
        "DALF_yuyan": {
            audio: "ext:约会大作战/audio:2",
            mod: {
                cardEnabled2: function (card) {
                    if (get.itemtype(card) == 'card' && card.hasGaintag('DALF_yuyan')) return false;
                },
            },
            init: function (player) {
                if (!player.DALF_yuyan) {
                    var list = [game.createCard(), game.createCard()];
                    var reupdate = function () {
                        try {
                            var cards = player.DALF_yuyan[1];
                            var currentChild = ui.cardPile.firstChild;
                            cards[1].init(currentChild);
                            cards[1].classList.add('glows');
                            cards[1].classList.remove('selectable');
                            currentChild = currentChild.nextElementSibling;
                            if (currentChild) {
                                cards[0].init(currentChild);
                                cards[0].classList.add('glows');
                                cards[0].classList.remove('selectable');
                            }
                        } catch (e) {

                        }
                    };
                    player.DALF_yuyan = [setInterval(reupdate, 500), list];
                    setTimeout(function () {
                        player.directgain(list, true, 'DALF_yuyan');
                    }, 750);
                    game.broadcast(function (DALF_yuyan) {
                        player.DALF_yuyan = DALF_yuyan;
                    }, player, player.DALF_yuyan);
                }
            },
            remove: function (player) {
                if (player.DALF_yuyan) {
                    game.broadcast(function (player) {
                        clearInterval(player.DALF_yuyan[0]);
                        delete player.DALF_yuyan;
                    }, player);
                }
            },
            trigger: {
                global: "judgeBefore",
            },
            filter: function (event, player) {
                return true;
            },
            forced: true,
            content: function () {
                "step 0"
                event.cards = [];
                for (var i = 0; i < ui.cardPile.childElementCount; i++) {
                    event.cards.push(ui.cardPile.childNodes[i]);
                    if (event.cards.length > 1) break;
                }
                var tip = '预言：' + get.translation(trigger.player) + '即将进行' + (trigger.judgestr || '') + '判定，请选择要置顶的牌';
                var next = player.chooseButton(true, [tip, event.cards, 'hidden']);
                next.ai = function (button) {
                    if (get.attitude(player, trigger.player) > 0) {
                        return 1 + trigger.judge(button.link);
                    }
                    if (get.attitude(player, trigger.player) < 0) {
                        return 1 - trigger.judge(button.link);
                    }
                    return 0;
                };
                "step 1"
                ui.cardPile.insertBefore(result.links[0], ui.cardPile.firstChild);
                "step 2"
                game.delay(1.5);
            },
            ai: {
                /*viewHandcard:true,
                skillTagFilter:function (player,tag,arg){
                    if(player==arg||_status.currentPhase!=arg) return false;
                },*/
            }
        },
        "DALF_jianlu": {
            audio: "ext:约会大作战/audio:2",
            trigger: {
                player: "useCardAfter",
            },
            frequent: function (event, player) {
                return !player.isPhaseUsing();
            },
            filter: function (event, player) {
                if (player.hasSkill('DALF_jianlu_off')) return false;
                if (get.itemtype(event.cards) != 'cards') return false;
                if (!event.cards || event.cards.length > 1 || !event.card.isCard) return false;
                return true;
            },
            content: function () {
                "step 0"
                if (player.isPhaseUsing()) player.addTempSkill('DALF_jianlu_off', { player: 'phaseUseAfter' });
                player.judge(function (card) {
                    if (get.color(card) != get.color(trigger.card)) {
                        if (game.hasPlayer(function (current) {
                            return player.canUse(card, current, true, true);
                        })) return player.getUseValue(card);
                        return -0.5;
                    }
                    if (get.suit(card) == get.suit(trigger.card)) return get.value(trigger.card) / 3;
                    return -1;
                });
                "step 1"
                if (result.suit == get.suit(trigger.card)) {
                    player.gain(trigger.cards, 'gain2').log = false;
                    game.log(player, '收回了', trigger.card);
                }
                if (result.color != get.color(trigger.card)) {
                    if (game.hasPlayer(function (current) {
                        return player.canUse(result.card, current, true, true);
                    })) player.chooseUseTarget(result.card).set('addCount', false);
                }
            },
            subSkill: { off: { sub: true } },
        },

        /*冰铠四糸乃*/
        "DALF_shiwen": {
            audio: "ext:约会大作战/audio:2",
            trigger: {
                player: "useCard1"
            },
            filter: function (event, player) {
                if (event.card.name == 'sha' && !game.hasNature(event.card)) return true;
            },
            check: function (event, player) {
                var eff = 1;
                //if(player.hasSkill('counttrigger'))
                for (var i = 0; i < event.targets.length; i++) {
                    var target = event.targets[i];
                    var eff1 = get.damageEffect(target, player, player, event.card.nature);
                    var eff2 = get.damageEffect(target, player, player, 'ice');
                    eff += eff2;
                    eff -= eff1;
                }
                return eff >= 0;
            },
            content: function () {
                "step 0"
                game.setNature(trigger.card, 'fire');
                if (get.itemtype(trigger.card) == 'card') {
                    var next = game.createEvent('DALF_shiwen_clear');
                    next.card = trigger.card;
                    event.next.remove(next);
                    trigger.after.push(next);
                    next.setContent(function (nature) {
                        game.setNature(trigger.card, []);
                    });
                }
                if (get.suit(trigger.card) == 'spade')
                    trigger.directHit.addArray(game.filterPlayer());
            },
            ai: {
                threaten: 1.4
            }
        },
        "DALF_jidong": {
            audio: "ext:约会大作战/audio:2",
            trigger: {
                global: "discardAfter"
            },
            direct: true,
            filter: function (event, player) {
                var evt = event.getParent(2);
                if (evt.parent.skill == 'icesha_skill' && player == evt.player) {
                    for (var i = 0; i < event.cards.length; i++) {
                        if (get.suit(event.cards[i]) == 'club') return true;
                    }
                }
                return false;
            },
            content: function () {
                "step 0"
                var next = player.chooseTarget();
                next.filterTarget = function (card, player, target) {
                    return player != target && target.countDiscardableCards(player, 'he');
                };
                next.ai = function (target) {
                    var player = _status.event.player;
                    var eff = 0;
                    if (target.hasCard(function (card) {
                        return get.suit(card) == 'club';
                    }, player.hasSkillTag('viewHandcard', null, target, true) ? 'he' : 'e')) eff = 3;
                    return -player.attitudeTo(target) + eff;
                };
                next.set('prompt', get.prompt2('DALF_jidong'));
                "step 1"
                if (result.bool) {
                    event.target = result.targets[0];
                    player.logSkill('DALF_jidong', result.targets);
                    var next = player.discardPlayerCard(result.targets[0], 'he', true);
                    next.ai = function (button) {
                        var value = 0;
                        if (_status.event.dameff >= 0) {
                            if (get.suit(button.link) == 'club') value = 3;
                        }
                        return get.value(button.link) + value;
                    };
                    next.set('prompt', '急冻：请弃置' + get.translation(result.targets[0]) + '一张牌');
                    next.set('prompt2', '若你弃置了♠牌，你对其造成一点伤害');
                    next.set('dameff', get.damageEffect(result.targets[0], player, player));
                }
                "step 2"
                if (result.bool) {
                    if (get.suit(result.links[0]) == 'club') event.target.damage();
                }
            },
            ai: {
                threaten: 1.4,
                effect: {
                    player: function (card, player, target, current) {
                        if (get.tag(card, 'natureDamage') &&
                            !get.tag(card, 'iceDamage')) return [0.95, 0, 1, 0];
                    }
                }
            },
            group: ["DALF_jidong_iceshaAi"],
            subSkill: {
                iceshaAi: {
                    charlotte: true,
                    trigger: {
                        player: "discardPlayerCardBegin"
                    },
                    priority: 95,
                    forced: true,
                    silent: true,
                    filter: function (event, player) {
                        if (event.autochoose && event.autochoose()) return false;
                        if (lib.filter.wuxieSwap(event)) return false;
                        if (_status.auto || !player.isUnderControl()) return false;
                        return event.getParent(2).skill == 'icesha_skill';
                    },
                    content: function () {
                        if (trigger.ai && typeof trigger.ai == 'function') {
                            var ai2 = trigger.ai;
                            trigger.ai = function (button) {
                                var value = 0;
                                if (get.suit(button.link) == 'club') value = 3;
                                return ai2(button) + value;
                            }
                        } else {
                            trigger.ai = function (button) {
                                var value = 0;
                                if (get.suit(button.link) == 'club') value = 3;
                                return get.value(button.link) + value;
                            }
                        }
                    },
                }
            },
        },
        "DALF_shuangding": {
            audio: "ext:约会大作战/audio:2",
            enable: "phaseUse",
            usable: 1,
            position: "h",
            filter: function (event, player) {
                return player.countCards('h', function (card) {
                    return get.itemtype(card) == 'card' && card.hasGaintag('DALF_shuangding_marktag');
                }) < 4;
            },
            filterCard: {
                color: "black"
            },
            check: function (card) {
                return 7 - get.value(card);
            },
            content: function () {
                player.draw().set('gaintag', ['DALF_shuangding_marktag']);
            },
            ai: {
                order: 10,
                result: {
                    player: 1
                },
                threaten: 1.1
            },
            group: ["DALF_shuangding_marktag"],
            subSkill: {
                marktag: {
                    charlotte: true,
                    /*
                    mod:{
                        ignoredHandcard:function (card,player){
                            if(get.itemtype(card)=='card'&&card.hasGaintag('DALF_shuangding_marktag')){
                                return true;
                            }
                        },
                        cardDiscardable:function (card,player,name){
                            if(name=='phaseDiscard'&&(get.itemtype(card)=='card'&&card.hasGaintag('DALF_shuangding_marktag'))){
                                return false;
                            }
                        }
                    },
                    */
                    trigger: {
                        player: "loseAfter",
                    },
                    usable: 4,
                    forced: true,
                    filter: function (event, player) {
                        //if(player==_status.currentPhase) return false;
                        if (event.name == 'gain' && event.player == player) return false;
                        var map = event.gaintag_map;
                        if (map) {
                            for (var i in map) {
                                if (map[i].includes('DALF_shuangding_marktag')) return true;
                            }
                        }
                        return false;
                    },
                    content: function () {
                        "step 0"
                        player.draw().set('gaintag', ['DALF_shuangding_marktag']);
                        if (player != _status.currentPhase) player.changeHujia(1);
                    },
                    sub: true
                }
            }
        },

    }
}